package com.gangquan360.smartadmin.module.product.controller;

import com.gangquan360.smartadmin.common.anno.NoValidPrivilege;
import com.gangquan360.smartadmin.common.domain.PageResultDTO;
import com.gangquan360.smartadmin.common.domain.ResponseDTO;
import com.gangquan360.smartadmin.constant.SwaggerTagConst;
import com.gangquan360.smartadmin.module.product.domain.dto.ProductCategoryDTO;
import com.gangquan360.smartadmin.module.product.domain.dto.ProductCategoryQueryDTO;
import com.gangquan360.smartadmin.module.product.domain.dto.ProductCategoryVO;
import com.gangquan360.smartadmin.module.product.service.ProductCategoryService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import javax.validation.Valid;

/**
 * [ 产品分类表 ]
 *
 * @author wiggin
 * @version 1.0
 * @company wiggin
 * @copyright (c) 2019 wigginInc. All rights reserved.
 * @date 2020-03-14 21:32:22
 * @since JDK1.8
 */
@RestController
@Api(tags = {SwaggerTagConst.Group2.PRODUCT_CATEGORY_MANGER})
public class ProductCategoryController {

    @Autowired
    private ProductCategoryService productCategoryService;

    @ApiOperation(value = "分页查询产品分类表",notes = "@author wiggin")
    @PostMapping("/product/category/page/query")
    public ResponseDTO<PageResultDTO<ProductCategoryDTO>> queryByPage(@RequestBody ProductCategoryQueryDTO queryDTO) {
        return productCategoryService.queryByPage(queryDTO);
    }
    
    @ApiOperation("获取分类树")
    @GetMapping("/product/category/tree")
    @NoValidPrivilege
    public ResponseDTO<List<ProductCategoryVO>> getTree() {
    	return productCategoryService.getTree();
    }
    

    @ApiOperation(value = "添加产品分类表",notes = "@author wiggin")
    @PostMapping("/product/category/add")
    public ResponseDTO<String> add(@RequestBody @Valid ProductCategoryDTO addTO){
        return productCategoryService.add(addTO);
    }

    @ApiOperation(value="修改产品分类表",notes = "@author wiggin")
    @PostMapping("/product/category/update")
    public ResponseDTO<String> update(@RequestBody @Valid ProductCategoryDTO updateDTO){
        return productCategoryService.update(updateDTO);
    }


    @ApiOperation(value="删除产品分类表",notes = "@author wiggin")
    @GetMapping("/product/category/delete/{id}")
    public ResponseDTO<String> delete(@PathVariable("id") Long id){
        return productCategoryService.delete(id);
    }


    @ApiOperation(value="详情产品分类表",notes = "@author wiggin")
    @GetMapping("/product/category/detail/{id}")
    public ResponseDTO<ProductCategoryDTO> detail(@PathVariable("id") Long id){
        return productCategoryService.detail(id);
    }
}
